<template>
  <div class="home">
    <!-- 轮播 -->
    <van-swipe
      class="my-swipe"
      :autoplay="3000"
      indicator-color="white"
    >
      <van-swipe-item
        v-for="item in lunbolist"
        :key="item.id"
      >
        <img
          :src="item.img"
          alt=""
        >
      </van-swipe-item>
    </van-swipe>
    <!-- 九宫格 -->
    <van-grid :column-num="3">
      <van-grid-item
        v-for="grid in grids"
        :key="grid.id"
        :icon="grid.src"
        :text="grid.title"
      />
    </van-grid>
  </div>
</template>
<script>
// import axios from 'axios'
import { getLunbo, getGrids } from '../../api/home'
// import { Toast } from 'vant'
export default {
  data: () => ({
    lunbolist: [],
    grids: []
  }),
  created() {
    this.getLunbo()
    this.getGrids()
  },
  methods: {
    async getLunbo() {
      // try {
      //   const res = await axios.get('http://itfly.vip:8888/api/getlunbo')
      //   this.lunbolist = res.data.message
      // } catch (error) {
      //   Toast('资源请求失败')
      // }
      const res = await getLunbo()
      this.lunbolist = res.data.message
    },
    async getGrids() {
      // try {
      //   const res = await axios.get('http://itfly.vip:8888/api/grids')
      //   this.grids = res.data.message
      // } catch (error) {
      //   Toast('资源请求失败')
      // }
      const res = await getGrids()
      this.grids = res.data.message
    }
  }
}
</script>
<style lang="less" >
.home {
  .my-swipe .van-swipe-item {
    height: 200px;
    line-height: 200px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .van-grid-item__icon {
    font-size: 50px;
  }
}
</style>
